﻿#region Using directives
using System.Collections.Generic;
using System.Linq;
using Blazorise.Providers;
#endregion

namespace Blazorise.Icons.Material;

class MaterialIconProvider : BaseIconProvider
{
    #region Members

    private static Dictionary<IconName, string> names = new()
    {
        { IconName.Add, MaterialIcons.Add },
        { IconName.Adjust, MaterialIcons.Adjust },
        { IconName.Alert, MaterialIcons.Notifications },
        { IconName.AlertOff, MaterialIcons.NotificationsOff },
        { IconName.AlignCenter, MaterialIcons.FormatAlignCenter },
        { IconName.AlignJustify, MaterialIcons.FormatAlignJustify },
        { IconName.AlignLeft, MaterialIcons.FormatAlignLeft },
        { IconName.AlignRight, MaterialIcons.FormatAlignRight },
        { IconName.AngleDown, MaterialIcons.ArrowDropDown },
        { IconName.AngleLeft, MaterialIcons.KeyboardArrowLeft },
        { IconName.AngleRight, MaterialIcons.KeyboardArrowRight },
        { IconName.AngleUp, MaterialIcons.ArrowDropUp },
        { IconName.Apple, MaterialIcons.Apple },
        { IconName.Archive, MaterialIcons.Archive },
        { IconName.ArrowAltCircleDown, MaterialIcons.ArrowDropDownCircle },
        { IconName.ArrowDown, MaterialIcons.ArrowDownward },
        { IconName.ArrowLeft, MaterialIcons.ArrowBack },
        { IconName.ArrowRight, MaterialIcons.Forward },
        { IconName.ArrowUp, MaterialIcons.ArrowUpward },
        { IconName.Baby, MaterialIcons.ChildCare },
        { IconName.BabyCarriage, MaterialIcons.ChildFriendly },
        { IconName.Backspace, MaterialIcons.Backspace },
        { IconName.Backward, MaterialIcons.FastRewind },
        { IconName.BalanceScale, MaterialIcons.AccountBalance },
        { IconName.Ban, MaterialIcons.Block },
        { IconName.BandAid, MaterialIcons.Healing },
        { IconName.Bars, MaterialIcons.Menu },
        { IconName.BatteryFull, MaterialIcons.BatteryFull },
        { IconName.Bell, MaterialIcons.Notifications },
        { IconName.BellSlash, MaterialIcons.NotificationsOff },
        { IconName.Biking, MaterialIcons.DirectionsBike },
        { IconName.BirthdayCake, MaterialIcons.Cake },
        { IconName.Bold, MaterialIcons.FormatBold },
        { IconName.Bolt, MaterialIcons.FlashOn },
        { IconName.Book, MaterialIcons.Book },
        { IconName.Bookmark, MaterialIcons.Bookmark },
        { IconName.BookReader, MaterialIcons.Class },
        { IconName.BorderAll, MaterialIcons.BorderAll },
        { IconName.BorderNone, MaterialIcons.BorderClear },
        { IconName.BorderStyle, MaterialIcons.BorderStyle },
        { IconName.Briefcase, MaterialIcons.Work },
        { IconName.Brush, MaterialIcons.Brush },
        { IconName.Bug, MaterialIcons.BugReport },
        { IconName.Building, MaterialIcons.Business },
        { IconName.Bus, MaterialIcons.DirectionsBus },
        { IconName.Calendar, MaterialIcons.Event },
        { IconName.CalendarCheck, MaterialIcons.EventAvailable },
        { IconName.CalendarDay, MaterialIcons.ViewDay },
        { IconName.CalendarTimes, MaterialIcons.EventBusy },
        { IconName.CalendarWeek, MaterialIcons.ViewWeek },
        { IconName.Camera, MaterialIcons.Camera },
        { IconName.CameraRetro, MaterialIcons.CameraAlt },
        { IconName.Car, MaterialIcons.DirectionsCar },
        { IconName.CaretSquareRight, MaterialIcons.Slideshow },
        { IconName.Cart, MaterialIcons.ShoppingCart },
        { IconName.CartMinus, MaterialIcons.RemoveShoppingCart },
        { IconName.CartPlus, MaterialIcons.AddShoppingCart },
        { IconName.Chair, MaterialIcons.EventSeat },
        { IconName.ChartArea, MaterialIcons.AreaChart },
        { IconName.ChartBar, MaterialIcons.BarChart },
        { IconName.ChartLine, MaterialIcons.ShowChart },
        { IconName.ChartPie, MaterialIcons.PieChart },
        { IconName.ChartScatter, MaterialIcons.ScatterPlot },
        { IconName.Check, MaterialIcons.Check },
        { IconName.CheckCircle, MaterialIcons.CheckCircle },
        { IconName.CheckDouble, MaterialIcons.DoneAll },
        { IconName.CheckSquare, MaterialIcons.CheckBox },
        { IconName.ChevronLeft, MaterialIcons.ChevronLeft },
        { IconName.ChevronRight, MaterialIcons.ChevronRight },
        { IconName.ChevronUp, MaterialIcons.ExpandLess },
        { IconName.ChevronDown, MaterialIcons.ExpandMore },
        { IconName.Circle, MaterialIcons.RadioButtonUnchecked },
        { IconName.City, MaterialIcons.LocationCity },
        { IconName.Clear, MaterialIcons.Clear },
        { IconName.ClinicMedical, MaterialIcons.LocalPharmacy },
        { IconName.Clipboard, MaterialIcons.Assignment },
        { IconName.Clock, MaterialIcons.Schedule },
        { IconName.ClosedCaptioning, MaterialIcons.ClosedCaption },
        { IconName.Cloud, MaterialIcons.Cloud },
        { IconName.CloudDownloadAlt, MaterialIcons.CloudDownload },
        { IconName.CloudUploadAlt, MaterialIcons.Backup },
        { IconName.Cocktail, MaterialIcons.LocalBar },
        { IconName.Code, MaterialIcons.Code },
        { IconName.Coffee, MaterialIcons.LocalCafe },
        { IconName.Comment, MaterialIcons.Comment },
        { IconName.CommentAlt, MaterialIcons.Comment },
        { IconName.Comments, MaterialIcons.Chat },
        { IconName.CompactDisc, MaterialIcons.Album },
        { IconName.Compass, MaterialIcons.Explore },
        { IconName.Compress, MaterialIcons.FullscreenExit },
        { IconName.Copy, MaterialIcons.ContentCopy },
        { IconName.Copyright, MaterialIcons.Copyright },
        { IconName.CreditCard, MaterialIcons.CreditCard },
        { IconName.Crop, MaterialIcons.Crop },
        { IconName.Cut, MaterialIcons.ContentCut },
        { IconName.Dashboard, MaterialIcons.Dashboard },
        { IconName.Delete, MaterialIcons.Delete },
        { IconName.Desktop, MaterialIcons.Computer },
        { IconName.Dice, MaterialIcons.Casino },
        { IconName.Directions, MaterialIcons.Directions },
        { IconName.Dog, MaterialIcons.Pets },
        { IconName.DollarSign, MaterialIcons.AttachMoney },
        { IconName.DotCircle, MaterialIcons.RadioButtonChecked },
        { IconName.Download, MaterialIcons.GetApp },
        { IconName.Dumbbell, MaterialIcons.FitnessCenter },
        { IconName.Edit, MaterialIcons.Edit },
        { IconName.Eject, MaterialIcons.Eject },
        { IconName.Ethernet, MaterialIcons.SettingsEthernet },
        { IconName.EuroSign, MaterialIcons.EuroSymbol },
        { IconName.Exclamation, MaterialIcons.PriorityHigh },
        { IconName.ExclamationCircle, MaterialIcons.Error },
        { IconName.ExclamationTriangle, MaterialIcons.ReportProblem },
        { IconName.Expand, MaterialIcons.Fullscreen },
        { IconName.ExpandArrowsAlt, MaterialIcons.ZoomOutMap },
        { IconName.ExpandLess, MaterialIcons.ExpandLess },
        { IconName.ExpandMore, MaterialIcons.ExpandMore },
        { IconName.ExternalLinkSquareAlt, MaterialIcons.Publish },
        { IconName.Eye, MaterialIcons.Visibility },
        { IconName.EyeSlash, MaterialIcons.VisibilityOff },
        { IconName.FastBackward, MaterialIcons.FastRewind },
        { IconName.FastForward, MaterialIcons.FastForward },
        { IconName.File, MaterialIcons.Description },
        { IconName.FileAlt, MaterialIcons.Description },
        { IconName.FileDownload, MaterialIcons.FileDownload },
        { IconName.FilePdf, MaterialIcons.PictureAsPdf },
        { IconName.FileUpload, MaterialIcons.FileUpload },
        { IconName.Film, MaterialIcons.Theaters },
        { IconName.Filter, MaterialIcons.FilterAlt },
        { IconName.Fingerprint, MaterialIcons.Fingerprint },
        { IconName.Fire, MaterialIcons.Whatshot },
        { IconName.Flag, MaterialIcons.Flag },
        { IconName.Flask, MaterialIcons.Science },
        { IconName.Folder, MaterialIcons.Folder },
        { IconName.FolderOpen, MaterialIcons.FolderOpen },
        { IconName.FolderPlus, MaterialIcons.CreateNewFolder },
        { IconName.Forward, MaterialIcons.Forward },
        { IconName.Frown, MaterialIcons.MoodBad },
        { IconName.FrownOpen, MaterialIcons.SentimentDissatisfied },
        { IconName.Gamepad, MaterialIcons.Gamepad },
        { IconName.GasPump, MaterialIcons.LocalGasStation },
        { IconName.Gavel, MaterialIcons.Gavel },
        { IconName.Gift, MaterialIcons.CardGiftcard },
        { IconName.Globe, MaterialIcons.Language },
        { IconName.Grin, MaterialIcons.Face },
        { IconName.GripLines, MaterialIcons.DragHandle },
        { IconName.GripVertical, MaterialIcons.DragIndicator },
        { IconName.HandPaper, MaterialIcons.PanTool },
        { IconName.HandsHelping, MaterialIcons.LiveHelp },
        { IconName.Headphones, MaterialIcons.Headset },
        { IconName.Headset, MaterialIcons.Headset },
        { IconName.Heart, MaterialIcons.Favorite },
        { IconName.Highlighter, MaterialIcons.Highlight },
        { IconName.History, MaterialIcons.History },
        { IconName.Home, MaterialIcons.Home },
        { IconName.Hospital, MaterialIcons.LocalHospital },
        { IconName.Hotel, MaterialIcons.Hotel },
        { IconName.HotTub, MaterialIcons.HotTub },
        { IconName.Hourglass, MaterialIcons.HourglassEmpty },
        { IconName.IdCard, MaterialIcons.CardMembership },
        { IconName.Image, MaterialIcons.Image },
        { IconName.Images, MaterialIcons.PhotoAlbum },
        { IconName.Inbox, MaterialIcons.Inbox },
        { IconName.Indent, MaterialIcons.FormatIndentIncrease },
        { IconName.Infinity, MaterialIcons.AllInclusive },
        { IconName.Info, MaterialIcons.Info },
        { IconName.InfoCircle, MaterialIcons.Info },
        { IconName.Italic, MaterialIcons.FormatItalic },
        { IconName.Key, MaterialIcons.VpnKey },
        { IconName.Keyboard, MaterialIcons.Keyboard },
        { IconName.Language, MaterialIcons.Language },
        { IconName.Laptop, MaterialIcons.Laptop },
        { IconName.LaptopCode, MaterialIcons.DeveloperMode },
        { IconName.Laugh, MaterialIcons.InsertEmoticon },
        { IconName.LayerGroup, MaterialIcons.Layers },
        { IconName.Lightbulb, MaterialIcons.WbIncandescent },
        { IconName.Link, MaterialIcons.Link },
        { IconName.List, MaterialIcons.List },
        { IconName.ListOl, MaterialIcons.FormatListNumbered },
        { IconName.ListUl, MaterialIcons.FormatListBulleted },
        { IconName.LocationArrow, MaterialIcons.Navigation },
        { IconName.Lock, MaterialIcons.Lock },
        { IconName.LockOpen, MaterialIcons.LockOpen },
        { IconName.Mail, MaterialIcons.Mail },
        { IconName.MailOpen, MaterialIcons.MailOutline },
        { IconName.Map, MaterialIcons.Map },
        { IconName.MapMarker, MaterialIcons.MyLocation },
        { IconName.MapMarkerAlt, MaterialIcons.Room },
        { IconName.Memory, MaterialIcons.Memory },
        { IconName.Microphone, MaterialIcons.Mic },
        { IconName.MicrophoneSlash, MaterialIcons.MicOff },
        { IconName.MinusCircle, MaterialIcons.RemoveCircle },
        { IconName.MinusSquare, MaterialIcons.IndeterminateCheckBox },
        { IconName.MoneyBillAlt, MaterialIcons.LocalAtm },
        { IconName.Moon, MaterialIcons.Nightlife },
        { IconName.MoreHorizontal, MaterialIcons.MoreHoriz },
        { IconName.MoreVertical, MaterialIcons.MoreVert },
        { IconName.Motorcycle, MaterialIcons.Motorcycle },
        { IconName.Mouse, MaterialIcons.Mouse },
        { IconName.Music, MaterialIcons.MusicNote },
        { IconName.PaintBrush, MaterialIcons.Brush },
        { IconName.PaintRoller, MaterialIcons.FormatPaint },
        { IconName.Palette, MaterialIcons.Palette },
        { IconName.Paperclip, MaterialIcons.AttachFile },
        { IconName.PaperPlane, MaterialIcons.Send },
        { IconName.Parking, MaterialIcons.LocalParking },
        { IconName.Paste, MaterialIcons.ContentPaste },
        { IconName.Pause, MaterialIcons.Pause },
        { IconName.PauseCircle, MaterialIcons.PauseCircleFilled },
        { IconName.Pen, MaterialIcons.Edit },
        { IconName.Phone, MaterialIcons.Phone },
        { IconName.PhoneAlt, MaterialIcons.Phone },
        { IconName.PizzaSlice, MaterialIcons.LocalPizza },
        { IconName.Plane, MaterialIcons.LocalAirport },
        { IconName.PlaneArrival, MaterialIcons.FlightLand },
        { IconName.PlaneDeparture, MaterialIcons.FlightTakeoff },
        { IconName.Play, MaterialIcons.PlayArrow },
        { IconName.PlayCircle, MaterialIcons.PlayCircleFilled },
        { IconName.Plug, MaterialIcons.Power },
        { IconName.PlusCircle, MaterialIcons.AddCircle },
        { IconName.PlusSquare, MaterialIcons.AddBox },
        { IconName.Poll, MaterialIcons.Poll },
        { IconName.Portrait, MaterialIcons.Portrait },
        { IconName.Print, MaterialIcons.Print },
        { IconName.PuzzlePiece, MaterialIcons.Extension },
        { IconName.QuestionCircle, MaterialIcons.Help },
        { IconName.QuoteRight, MaterialIcons.FormatQuote },
        { IconName.Random, MaterialIcons.Shuffle },
        { IconName.Receipt, MaterialIcons.Receipt },
        { IconName.Redo, MaterialIcons.Redo },
        { IconName.Remove, MaterialIcons.Remove },
        { IconName.RemoveFormat, MaterialIcons.FormatClear },
        { IconName.Reply, MaterialIcons.Reply },
        { IconName.ReplyAll, MaterialIcons.ReplyAll },
        { IconName.Restroom, MaterialIcons.Wc },
        { IconName.Rss, MaterialIcons.RssFeed },
        { IconName.RulerHorizontal, MaterialIcons.Straighten },
        { IconName.Running, MaterialIcons.DirectionsRun },
        { IconName.Satellite, MaterialIcons.Satellite },
        { IconName.Save, MaterialIcons.Save },
        { IconName.School, MaterialIcons.School },
        { IconName.Screenshot, MaterialIcons.CropFree },
        { IconName.SdCard, MaterialIcons.SdCard },
        { IconName.Search, MaterialIcons.Search },
        { IconName.SearchMinus, MaterialIcons.ZoomOut },
        { IconName.SearchPlus, MaterialIcons.ZoomIn },
        { IconName.Seedling, MaterialIcons.LocalFlorist },
        { IconName.Send, MaterialIcons.Send },
        { IconName.Server, MaterialIcons.Dns },
        { IconName.Settings, MaterialIcons.Settings },
        { IconName.Shapes, MaterialIcons.FormatShapes },
        { IconName.Share, MaterialIcons.Share },
        { IconName.ShareAlt, MaterialIcons.Share },
        { IconName.Shield, MaterialIcons.Security },
        { IconName.ShieldAlt, MaterialIcons.Security },
        { IconName.Ship, MaterialIcons.DirectionsBoat },
        { IconName.ShoppingBag, MaterialIcons.Shop },
        { IconName.ShoppingBasket, MaterialIcons.ShoppingBasket },
        { IconName.ShoppingCart, MaterialIcons.ShoppingCart },
        { IconName.ShuttleVan, MaterialIcons.AirportShuttle },
        { IconName.SimCard, MaterialIcons.SimCard },
        { IconName.SliderHorizontal, MaterialIcons.Tune },
        { IconName.Smartphone, MaterialIcons.Smartphone },
        { IconName.Smile, MaterialIcons.Mood },
        { IconName.Smoking, MaterialIcons.SmokingRooms },
        { IconName.SmokingBan, MaterialIcons.SmokeFree },
        { IconName.Sms, MaterialIcons.Sms },
        { IconName.Snowflake, MaterialIcons.AcUnit },
        { IconName.Sort, MaterialIcons.Sort },
        { IconName.SortAlphaDown, MaterialIcons.ArrowDownward },
        { IconName.SortAlphaUp, MaterialIcons.ArrowUpward },
        { IconName.SortAmountDownAlt, MaterialIcons.Sort },
        { IconName.SortDown, MaterialIcons.ArrowDropDown },
        { IconName.SortUp, MaterialIcons.ArrowDropUp },
        { IconName.Spa, MaterialIcons.Spa },
        { IconName.SpellCheck, MaterialIcons.Spellcheck },
        { IconName.Square, MaterialIcons.CheckBoxOutlineBlank },
        { IconName.Star, MaterialIcons.Star },
        { IconName.StarHalf, MaterialIcons.StarHalf },
        { IconName.StepBackward, MaterialIcons.SkipPrevious },
        { IconName.StepForward, MaterialIcons.SkipNext },
        { IconName.StickyNote, MaterialIcons.NoteAdd },
        { IconName.Stop, MaterialIcons.Stop },
        { IconName.Store, MaterialIcons.Store },
        { IconName.StoreAlt, MaterialIcons.StoreMallDirectory },
        { IconName.Stream, MaterialIcons.ViewStream },
        { IconName.StreetView, MaterialIcons.Streetview },
        { IconName.Strikethrough, MaterialIcons.FormatStrikethrough },
        { IconName.Subscript, MaterialIcons.Subscriptions },
        { IconName.Subway, MaterialIcons.Subway },
        { IconName.Suitcase, MaterialIcons.BusinessCenter },
        { IconName.Sun, MaterialIcons.WbSunny },
        { IconName.Superscript, MaterialIcons.Superscript },
        { IconName.SwimmingPool, MaterialIcons.Pool },
        { IconName.Sync, MaterialIcons.Sync },
        { IconName.SyncAlt, MaterialIcons.Cached },
        { IconName.Table, MaterialIcons.TableView },
        { IconName.Tablet, MaterialIcons.Tablet },
        { IconName.Tag, MaterialIcons.LocalOffer },
        { IconName.Taxi, MaterialIcons.LocalTaxi },
        { IconName.TextHeight, MaterialIcons.FormatSize },
        { IconName.ThumbsDown, MaterialIcons.ThumbDown },
        { IconName.ThumbsUp, MaterialIcons.ThumbUp },
        { IconName.Ticket, MaterialIcons.ConfirmationNumber },
        { IconName.TicketAlt, MaterialIcons.LocalActivity },
        { IconName.Times, MaterialIcons.Close },
        { IconName.TimesCircle, MaterialIcons.HighlightOff },
        { IconName.Tint, MaterialIcons.InvertColors },
        { IconName.TintSlash, MaterialIcons.InvertColorsOff },
        { IconName.TrafficLight, MaterialIcons.Traffic },
        { IconName.Train, MaterialIcons.Train },
        { IconName.Tram, MaterialIcons.Tram },
        { IconName.Tree, MaterialIcons.Nature },
        { IconName.Truck, MaterialIcons.LocalShipping },
        { IconName.Tv, MaterialIcons.Tv },
        { IconName.UmbrellaBeach, MaterialIcons.BeachAccess },
        { IconName.Underline, MaterialIcons.FormatUnderlined },
        { IconName.Undo, MaterialIcons.Undo },
        { IconName.Unlock, MaterialIcons.NoEncryption },
        { IconName.User, MaterialIcons.Person },
        { IconName.UserCheck, MaterialIcons.VerifiedUser },
        { IconName.UserCircle, MaterialIcons.AccountCircle },
        { IconName.UserFriends, MaterialIcons.Group },
        { IconName.UserPlus, MaterialIcons.GroupAdd },
        { IconName.Users, MaterialIcons.GroupWork },
        { IconName.UserTie, MaterialIcons.SupervisorAccount },
        { IconName.Utensils, MaterialIcons.Restaurant },
        { IconName.Video, MaterialIcons.Videocam },
        { IconName.VideoSlash, MaterialIcons.VideocamOff },
        { IconName.Voicemail, MaterialIcons.Voicemail },
        { IconName.VolumeDown, MaterialIcons.VolumeDown },
        { IconName.VolumeMute, MaterialIcons.VolumeMute },
        { IconName.VolumeOff, MaterialIcons.VolumeOff },
        { IconName.VolumeUp, MaterialIcons.VolumeUp },
        { IconName.Walking, MaterialIcons.DirectionsWalk },
        { IconName.Wallet, MaterialIcons.AccountBalanceWallet },
        { IconName.Wheelchair, MaterialIcons.Accessible },
        { IconName.Wifi, MaterialIcons.Wifi },
        { IconName.WineBottle, MaterialIcons.LocalDrink },
        { IconName.Wrench, MaterialIcons.Build },
        { IconName.Zoom, MaterialIcons.Search },
        { IconName.ZoomIn, MaterialIcons.ZoomIn },
        { IconName.ZoomOut, MaterialIcons.ZoomOut },
    };

    private static Dictionary<IconStyle, string> styles = new()
    {
        { IconStyle.Solid, "material-icons" },
        { IconStyle.Regular, "material-icons-outlined" },
        { IconStyle.Light, "material-icons-sharp" }, // TODO: probably not correct
        { IconStyle.DuoTone, "material-icons-two-tone" },
    };

    // Some material icons have a special outline names so we need to override them.
    private static Dictionary<string, string> outlineNameOverrides = new()
    {
        { "star", "star_outline" }
    };

    #endregion

    #region Methods

    public override string IconSize( IconSize iconSize )
    {
        return iconSize switch
        {
            Blazorise.IconSize.ExtraSmall => "md-xs",
            Blazorise.IconSize.Small => "md-sm",
            Blazorise.IconSize.Large => "md-lg",
            Blazorise.IconSize.x2 => "md-2x",
            Blazorise.IconSize.x3 => "md-3x",
            Blazorise.IconSize.x4 => "md-4x",
            Blazorise.IconSize.x5 => "md-5x",
            Blazorise.IconSize.x6 => "md-6x",
            Blazorise.IconSize.x7 => "md-7x",
            Blazorise.IconSize.x8 => "md-8x",
            Blazorise.IconSize.x9 => "md-9x",
            Blazorise.IconSize.x10 => "md-10x",
            _ => null,
        };
    }

    public override string GetIconName( IconName iconName, IconStyle iconStyle )
    {
        if ( names.TryGetValue( iconName, out var value ) )
        {
            if ( iconStyle == IconStyle.Regular && outlineNameOverrides.TryGetValue( value, out var valueOverride ) )
                return valueOverride;

            return value;
        }

        return null;
    }

    public override void SetIconName( IconName name, string newName )
    {
        names[name] = newName;
    }

    public override string GetStyleName( IconStyle iconStyle )
    {
        if ( styles.TryGetValue( iconStyle, out var style ) )
            return style;

        return null;
    }

    protected override bool ContainsStyleName( string iconName )
    {
        return iconName.Split( ' ' ).Any( x => styles.Values.Contains( x ) || new string[] { "material-icons-round" }.Contains( x ) );
    }

    #endregion

    #region Properties

    public override bool IconNameAsContent => true;

    #endregion
}